// pages/t_user/t_user.js
import request from '../../request/request.js'
Page({
  data: {
    active:2,
    coachInfo:'',
    awardList:{}
  },
  onChange(event) {
    // event.detail 的值为当前选中项的索引
    if(event.detail===1){
      wx.redirectTo({
        url: '../t_course/t_course'
      });
    }
    if(event.detail===0){
      wx.redirectTo({
        url: '../t_index/t_index'
      });
    }   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getRank();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  onShow: function () {
    let coachInfo = wx.getStorageSync('coachInfo');
    if(coachInfo==''){
      wx.navigateTo({url: '../t_login/t_login'})
    }
    this.setData({
      coachInfo:coachInfo
    })
  },
  loginOut(){
    wx.removeStorageSync('coachInfo');
    wx.navigateTo({url: '../login/login'})
  },
  getRank(){
    var that = this
    request({
      url:'coach/rank',
      method:'post'
    }).then(res=>{
      if(res.data.success){
        let list = res.data.data
        if(list.length>3){
          that.setData({awardList:list.slice(0,3)})
          that.setData({rankList:list.slice(3,list.length)})
          that.setData({hasList:true})
        }else{
          that.setData({awardList:list})
        }
      }
    }).catch(err=>{})
  },
  about(){
    wx.showToast({
      title: 'xxx：xxx',
      icon: 'none',
      duration: 1500,
      mask: false,
    });
  }
})